package com.mt.api.util;


import java.util.EnumSet;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;

public class EnumMappingUtil {

    private EnumMappingUtil() {
    }

    public static <T extends Enum<T>, K> Map<K, T> toMappingMap(Class<T> clz, Function<T, K> keyMapper) {
        Objects.requireNonNull(clz);
        Objects.requireNonNull(keyMapper);
        EnumSet<T> enums = EnumSet.allOf(clz);
        return enums.stream().collect(Collectors.toMap(keyMapper, Function.identity()));
    }
}
